package com.dduggs.activemq.queue;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

public class AppProducer {

    private static final String url="tcp://127.0.0.1:61616";
    private static final String quequName="queue-test";

    public static void main(String[] args) {
        ConnectionFactory connectionFactory=new ActiveMQConnectionFactory(url);
        Connection connection= null;
        try {
            connection = connectionFactory.createConnection();
            connection.start();
            Session session=connection.createSession(false,Session.AUTO_ACKNOWLEDGE);

            Destination destination= session.createQueue(quequName);
            MessageProducer producer=session.createProducer(destination);
            for (int i = 0; i < 100; i++) {

                TextMessage textMessage=session.createTextMessage("test"+i);
                producer.send(textMessage);
                System.out.println("send ==="+textMessage.getText());
            }
            connection.close();
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}
